package com.reflect.study;

import com.reflect.study.entity.User;

import java.lang.reflect.Constructor;

public class Test2 {
    public static void main(String[] args) throws Exception {
        Class<?> userClass = Class.forName("com.reflect.study.entity.User");

        // 获取无参构造函数
        User user1 = (User) userClass.newInstance();
        System.out.println(user1);

        // 获取有参构造函数
        Constructor<?> user2 = userClass.getDeclaredConstructor(String.class, String.class, Integer.class);
        User user3 = (User) user2.newInstance("qxf","12345",111);
        System.out.println(user3);

    }
}
